package com.douya.pangu.application.config;

import com.douya.pangu.application.sys.PanGuWebSocketHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * websocket配置
 *
 * @Author hcy
 * @Date 2023/3/22
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 支持websocket的访问链接
        registry.addHandler(
                        new PanGuWebSocketHandler(), "/websocket/core"
                )
                .setAllowedOrigins("*");
        // 支持sockjs的访问链接
        registry.addHandler(
                        new PanGuWebSocketHandler(), "/sockjs/core"
                )
                .setAllowedOrigins("*")
                .withSockJS();
    }
}
